﻿using System;
using System.Linq;

namespace CDOP.Model
{

    public partial class UserDetails
    {
        private readonly CDOPEntities _db = new CDOPEntities();

        public int SaveUser(UserDetails userToSave, string userType)
        {
            try
            {
                var type = _db.UserType.Where(x => x.Type.ToLower() == userType).FirstOrDefault();
                userToSave.UserType = type;
                if (userToSave.id == 0)
                    _db.AddToUserDetails(userToSave);
                _db.SaveChanges();
                return userToSave.id;
            }
            catch (Exception)
            {
                return 0;
            }
        }

        public bool TryToGetAuthenticationByEmail(string email, out UserDetails user)
        {
            user = _db.UserDetails.Where(x => x.Email == email).FirstOrDefault();
            return user != null;
        }

      
    }
}